﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace e3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog myFile = new OpenFileDialog();
            myFile.Multiselect = true;
         if (myFile.ShowDialog() != DialogResult.OK)
            {
                return;
            }
    
            // 读取两个文件的内容
            string[] contents = new string[2];
            for (int i = 0; i < 2; i++)
            {
                try
                {
                    using (StreamReader sr = new StreamReader(myFile.FileNames[i]))
                    {
                        contents[i] = sr.ReadToEnd();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("读取文件时出错：" + ex.Message);
                    return;
                }
            }

            // 合并两个文件的内容
            string newContent = contents[0] + contents[1];

            // 写入新文件
            string newdate = Path.Combine(Application.StartupPath, "Data");
            Directory.CreateDirectory(newdate);
            string newpath = Path.Combine(newdate, "new.txt");
            try
            {
                using (StreamWriter sw = new StreamWriter(newpath))
                {
                    sw.Write(newContent);
                }
                MessageBox.Show("合并完成，新文件已保存到" + newpath);
            }
            catch (Exception ex)
            {
                MessageBox.Show("写入新文件时出错：" + ex.Message);
                return;
            }
        }
    }
}
